﻿using System;

namespace FunctionalCLR.Core.Functions.Maths {

    /// <summary>
    /// Find the max value among the list
    /// </summary>
    public class MaxNode : FuncNode {

        public MaxNode() {
            base.Value = "max";
        }

        public override object Evaluate() {
            double max = Double.MinValue;
            for (int index = 0; index < Children.Count; index++) {
                double value = Convert.ToDouble(
                    Children[index].Evaluate());
                if (value > max) {
                    max = value;
                }
            }

            return max;
        }
    }
}
